﻿/*********************************************
* 命名空间: DataCode.MongoDBProvide
* 功 能： 基于Abp的mongoDB模块
* 类 名： MongoDBModule
* 作 者:  东腾
* 时 间： 2018/2/24 14:59:04 
**********************************************
*/
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Abp.Configuration.Startup;
using Abp.Domain.Repositories;
using Abp.Modules;
using Abp.MongoDb;
using Abp.MongoDb.Repositories;
using Castle.MicroKernel.Registration;

namespace DataCode.MongoDBProvide
{
    [DependsOn(typeof(AbpMongoDbModule))]
    public class MongoDBModule:AbpModule
    {
        public override void PreInitialize()
        {
            var connStr = ConfigurationManager.ConnectionStrings["MongoServer"].ConnectionString;
            var database = ConfigurationManager.ConnectionStrings["MongoDatabase"].ConnectionString;
            //获取mongodb链接字符串
            Configuration.Modules.AbpMongoDb().ConnectionString = connStr;
            Configuration.Modules.AbpMongoDb().DatatabaseName = database;
        }
        public override void Initialize()
        {
            IocManager.IocContainer.Register(
                Component.For(typeof(IRepository<,>), typeof(MongoDbRepositoryBase<,>)).LifestyleTransient()
            );
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}
